= render 'backend/shared/financial_year_warning'

= kujaku do |k|
  - k.text
  - k.multi_choice :state, FixedAsset.state.values.map{|s| [s.human_name, s] }, label: FixedAsset.human_attribute_name(:state)
  - k.helper :journal_period_crit
  - p_ids = FixedAsset.all.pluck(:product_id).compact.uniq
  - products = Product.where(id: p_ids).reorder(:name)
  - if products.any?
    - k.helper do
      %label= Product.human_attribute_name(:name)
      = select_tag(:product_id, options_for_select([[]] + products.map{|u| [u.name, u.id]}, params[:product_id].to_i))

- main_toolbar do |t|
  = t.new params: { redirect: nil }, class: ("disabled" if FinancialYear.count == 0)

  %span.btn-group.action-form
    - depreciate_until = FinancialYear.opened.first&.stopped_on
    - max_date = FinancialYear.opened.last&.stopped_on
    = link_to :account_for.tl, { action: :depreciate_all, until: depreciate_until&.iso8601, redirect: request.fullpath }, { class: ['btn btn-default', ('disabled' if depreciate_until == nil)], data: { confirm: :are_you_sure.tl, update_link_with: '#depreciate-fixed-assets-until' }, method: :post }
    %span.add-on= :up_to.tl.downcase
    = date_field_tag(:until, depreciate_until, id: 'depreciate-fixed-assets-until', data: { max_date: FinancialYear.opened.any? ? max_date.iso8601 : Time.zone.today.iso8601 }, disabled: (true if FinancialYear.count == 0))

  = t.export :fixed_asset_registry, :by_account_fixed_asset_registry, :gain_and_loss_fixed_asset_registry, key: Printers::FixedAssetRegistryPrinter.build_key(stopped_on: params[:stopped_on])

= main_list
